<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

<html><head><title>Tips &amp; Tricks - NewAC</title><link rel="stylesheet" type="text/css" href="../../../styles/main.css"><script language=JavaScript src="../../../javascript/main.js"></script><script language=JavaScript src="../../../javascript/searchdata.js"></script></head><body class="ContentPage" onLoad="NDOnLoad()"><script language=JavaScript><!--
if (browserType) {document.write("<div class=" + browserType + ">");if (browserVer) {document.write("<div class=" + browserVer + ">"); }}// --></script>

<!--  Generated by Natural Docs, version 1.4 -->
<!--  http://www.naturaldocs.org  -->

<!-- saved from url=(0026)http://www.naturaldocs.org -->




<div id=Content><div class="CSection"><div class=CTopic id=MainTopic><h1 class=CTitle><a name="TipsTricks"></a>Tips &amp; Tricks</h1><div class=CBody><p>Here is a collection of hints and code snippets related to NewAC or audio processing in general.</p><h4 class=CHeading>Documentation Note</h4><p>If you&rsquo;re inserting a single snippet, put a new topic in the <a href="#Snippets" class=LSection id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">Snippets</a> section.&nbsp; If you&rsquo;ve got a mini-tutorial, make a new section.</p><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SMain"><td class=SEntry><a href="#TipsTricks" >Tips &amp; Tricks</a></td><td class=SDescription>Here is a collection of hints and code snippets related to NewAC or audio processing in general.</td></tr><tr class="SSection"><td class=SEntry><a href="#Snippets" >Snippets</a></td><td class=SDescription>Bits of code to do things related to NewAC.</td></tr><tr class="SGeneric SIndent1 SMarked"><td class=SEntry><a href="#How_to_make_an_indicator_component_more_responsive" >How to make an indicator component more responsive</a></td><td class=SDescription>When constructing an audio-processing chain always try to place an indicator component as close to the audio input/output component as possible. </td></tr><tr class="SGeneric SIndent1"><td class=SEntry><a href="#What_to_do_if_an_input_component_reports_premature_end_of_data" >What to do if an input component reports premature end of data</a></td><td class=SDescription>One possible reason for this may be an exception raised during components&rsquo; operation. </td></tr><tr class="SGeneric SIndent1 SMarked"><td class=SEntry><a href="#How_to_decrease_the_delay_before_audio_playback" >How to decrease the delay before audio playback</a></td><td class=SDescription>The TDXAudioOut component buffers its output in order to make it smoother. </td></tr><tr class="SGeneric SIndent1"><td class=SEntry><a href="#How_not_to_crash_or_hang_when_exiting_an_application" >How not to crash or hang when exiting an application</a></td><td class=SDescription>If you exit a NewAC application while it is playing without stopping it, it may crash or hang. </td></tr><tr class="SGeneric SIndent1 SMarked"><td class=SEntry><a href="#Create_Class_Based_on_Filename" >Create Class Based on Filename</a></td><td class=SDescription>These functions create a TAuFile component of a class based on the file extension of a filename.</td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>

<div class="CSection"><div class=CTopic><h2 class=CTitle><a name="Snippets"></a>Snippets</h2><div class=CBody><p>Bits of code to do things related to NewAC.</p><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SGeneric"><td class=SEntry><a href="#How_to_make_an_indicator_component_more_responsive" >How to make an indicator component more responsive</a></td><td class=SDescription>When constructing an audio-processing chain always try to place an indicator component as close to the audio input/output component as possible. </td></tr><tr class="SGeneric SMarked"><td class=SEntry><a href="#What_to_do_if_an_input_component_reports_premature_end_of_data" >What to do if an input component reports premature end of data</a></td><td class=SDescription>One possible reason for this may be an exception raised during components&rsquo; operation. </td></tr><tr class="SGeneric"><td class=SEntry><a href="#How_to_decrease_the_delay_before_audio_playback" >How to decrease the delay before audio playback</a></td><td class=SDescription>The TDXAudioOut component buffers its output in order to make it smoother. </td></tr><tr class="SGeneric SMarked"><td class=SEntry><a href="#How_not_to_crash_or_hang_when_exiting_an_application" >How not to crash or hang when exiting an application</a></td><td class=SDescription>If you exit a NewAC application while it is playing without stopping it, it may crash or hang. </td></tr><tr class="SGeneric"><td class=SEntry><a href="#Create_Class_Based_on_Filename" >Create Class Based on Filename</a></td><td class=SDescription>These functions create a TAuFile component of a class based on the file extension of a filename.</td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>

<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="How_to_make_an_indicator_component_more_responsive"></a>How to make an indicator component more responsive</h3><div class=CBody><p>When constructing an audio-processing chain always try to place an indicator component as close to the audio input/output component as possible.&nbsp; It should be the first component after AudioIn or the last componentbefore AudioOut.</p></div></div></div>

<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="What_to_do_if_an_input_component_reports_premature_end_of_data"></a>What to do if an input component reports premature end of data</h3><div class=CBody><p>One possible reason for this may be an exception raised during components&rsquo; operation.&nbsp; Don&rsquo;t forget to set the OnThreadException event handler and inspect an output component&rsquo;s ExceptionMessage property.</p></div></div></div>

<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="How_to_decrease_the_delay_before_audio_playback"></a>How to decrease the delay before audio playback</h3><div class=CBody><p>The TDXAudioOut component buffers its output in order to make it smoother.&nbsp; This buffering introduces some delay at the beginning of audio playback.</p><p>You can decrease the delay by decreasing the size of the TDXAudioOut buffer.&nbsp; The size of this buffer is set up by the &lt;DS_BUFFER_SIZE&gt; constant in ACS_DxAudio.pas.</p><p>If you decrease the buffer size you may also want to decrease the &lt;DS_POLLING_INTERVAL&gt; value which determines how often the component requests data from its input.</p></div></div></div>

<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="How_not_to_crash_or_hang_when_exiting_an_application"></a>How not to crash or hang when exiting an application</h3><div class=CBody><p>If you exit a NewAC application while it is playing without stopping it, it may crash or hang.&nbsp; To prevent this, provide an OnClose event handler for the form where NewAC components reside.&nbsp; In this hander call Stop methods for all output components.&nbsp; A typical OnClose handler might look like this.</p><blockquote><pre>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  DXAudioOut1.Stop(False);
end;</pre></blockquote><p>You pass Stop a False value if you are closing an application and don&rsquo;t want any events.&nbsp; Remember that it is not harmful to call Stop even when the output component is idle.</p></div></div></div>

<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="Create_Class_Based_on_Filename"></a>Create Class Based on Filename</h3><div class=CBody><p>These functions create a TAuFile component of a class based on the file extension of a filename.</p><blockquote><pre>uses
  ACS_Classes, ACS_smpeg, ACS_WavPack, ACS_Wave, ACS_FLAC, ACS_MAC, ACS_Vorbis;
...

function CreateInputFromExt(sFilename: string): TAuFileIn;
var
  sExt: string;
begin
  sExt := ExtractFileExt(sFilename);
  if sExt = '.wav' then
    Result := TWaveIn.Create(nil)
  else if sExt = '.wv' then
    Result := TWVIn.Create(nil)
  else if sExt = '.mp3' then
    Result := TMP3In.Create(nil)
  else if sExt = '.flac' then
    Result := TFLACIn.Create(nil)
  else if sExt = '.ape' then
    Result := TMACIn.Create(nil)
  else if sExt = '.ogg' then
    Result := TVorbisIn.Create(nil)
  else
    Result := nil;
end;

function CreateOutputFromExt(sFilename: string): TAuFileOut;
var
  sExt: string;
begin
  sExt := ExtractFileExt(sFilename);
  if sExt = '.wav' then
    Result := TWaveOut.Create(nil)
  else if sExt = '.wv' then
    Result := TWVOut.Create(nil)
//TODO: Find out what is used to play MP3s
//  else if sExt = '.mp3' then
//    Result := TMP3Out.Create(nil)
  else if sExt = '.flac' then
    Result := TFLACOut.Create(nil)
  else if sExt = '.ape' then
    Result := TMACOut.Create(nil)
  else if sExt = '.ogg' then
    Result := TVorbisOut.Create(nil)
  else
    Result := nil;
end;</pre></blockquote></div></div></div>

</div><!--Content-->


<div id=Footer>Content &copy; 2008-2010 Andrei Borovsky. Design &copy; 2008 Wayne Thursby. <b><u><a href="http://symmetrica.net/newac">Go to the project's main page</a></u></b>&nbsp; &middot;&nbsp; <a href="http://www.naturaldocs.org">Generated by Natural Docs</a></div><!--Footer-->


<div id=Menu><div class=MTitle>NewAC<div class=MSubTitle>v2.5</div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent1')">Documentation</a><div class=MGroupContent id=MGroupContent1><div class=MEntry><div class=MFile><a href="introduction-txt.html">Quick Introduction to NewAC</a></div></div><div class=MEntry><div class=MFile><a href="about_documentation-txt.html">About the Documentation</a></div></div><div class=MEntry><div class=MFile><a href="cwguide-txt.html">Component Writer&rsquo;s Guide</a></div></div><div class=MEntry><div class=MFile><a href="license-txt.html">License</a></div></div><div class=MEntry><div class=MFile id=MSelected>Tips &amp; Tricks</div></div><div class=MEntry><div class=MFile><a href="newac-txt.html">About New Audio Components</a></div></div><div class=MEntry><div class=MFile><a href="features-txt.html">NewAC Main Features List</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent2')">Main Units</a><div class=MGroupContent id=MGroupContent2><div class=MEntry><div class=MFile><a href="../../src/ACS_AudioMix-pas.html">ACS_AudioMix</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_CDROM-pas.html">ACS_CDROM</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Classes-pas.html">ACS_Classes</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Converters-pas.html">ACS_Converters</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_DXAudio-pas.html">ACS_DXAudio</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_FLAC-pas.html">ACS_FLAC</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Filters-pas.html">ACS_Filters</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_LAME-pas.html">ACS_LAME</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_MAC-pas.html">ACS_MAC</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Misc-pas.html">ACS_Misc</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_MPC-pas.html">ACS_MPC</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_OptimFROG-pas.html">ACS_OptimFROG</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_smpeg-pas.html">ACS_SMPEG</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Streams-pas.html">ACS_Streams</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_TTA-pas.html">ACS_TTA</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Tags-pas.html">ACS_Tags</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Vorbis-pas.html">ACS_Vorbis</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_WavPack-pas.html">ACS_WavPack</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Wave-pas.html">ACS_Wave</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_WinMedia-pas.html">ACS_WinMedia</a></div></div><div class=MEntry><div class=MFile><a href="../../src/AudioDMO-pas.html">AudioDMO</a></div></div><div class=MEntry><div class=MFile><a href="../../src/AudioPass-pas.html">AudioPass</a></div></div><div class=MEntry><div class=MFile><a href="../../src/AuSampleRate-pas.html">AuSampleRate</a></div></div><div class=MEntry><div class=MFile><a href="../../src/AuASIO-pas.html">AuASIO</a></div></div><div class=MEntry><div class=MFile><a href="../../src/AuSynch-pas.html">AuSynch</a></div></div><div class=MEntry><div class=MFile><a href="../../src/NewACDTS-pas.html">NewACDTS</a></div></div><div class=MEntry><div class=MFile><a href="../../src/NewAC_AVI-pas.html">NewAC_AVI</a></div></div><div class=MEntry><div class=MFile><a href="../../src/NewAC_DSP-pas.html">NewAC_DSP</a></div></div><div class=MEntry><div class=MFile><a href="../../src/NewACAC3-pas.html">NewACAC3</a></div></div><div class=MEntry><div class=MFile><a href="../../src/NewACIndicators-pas.html">NewACIndicators</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent3')">Utility Units</a><div class=MGroupContent id=MGroupContent3><div class=MEntry><div class=MFile><a href="../../src/ACS_Misc-pas.html">ACS_Misc</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Procs-pas.html">ACS_Procs</a></div></div><div class=MEntry><div class=MFile><a href="../../src/acs_reg-pas.html">ACS_Reg</a></div></div><div class=MEntry><div class=MFile><a href="../../src/ACS_Types-pas.html">ACS_Types</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent4')">Tutorials</a><div class=MGroupContent id=MGroupContent4><div class=MEntry><div class=MFile><a href="../../demos/Tutorial/AudioProcessor/Main-pas.html">Audio Processor</a></div></div><div class=MEntry><div class=MFile><a href="../../demos/Tutorial/ComponentsDemo/ComponentsDemo-pas.html">Components Demo</a></div></div><div class=MEntry><div class=MFile><a href="../../demos/Recorders-rippers/Rip'n'listen/Main-pas.html">Rip&rsquo;n&rsquo;Listen Demo</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent5')">Index</a><div class=MGroupContent id=MGroupContent5><div class=MEntry><div class=MIndex><a href="../../../index/General.html">Everything</a></div></div><div class=MEntry><div class=MIndex><a href="../../../index/Classes.html">Classes</a></div></div><div class=MEntry><div class=MIndex><a href="../../../index/Constants.html">Constants</a></div></div><div class=MEntry><div class=MIndex><a href="../../../index/Functions.html">Functions</a></div></div><div class=MEntry><div class=MIndex><a href="../../../index/Properties.html">Properties</a></div></div><div class=MEntry><div class=MIndex><a href="../../../index/Types.html">Types</a></div></div><div class=MEntry><div class=MIndex><a href="../../../index/Variables.html">Variables</a></div></div></div></div></div><script type="text/javascript"><!--
var searchPanel = new SearchPanel("searchPanel", "HTML", "../../../search");
--></script><div id=MSearchPanel class=MSearchPanelInactive><input type=text id=MSearchField value=Search onFocus="searchPanel.OnSearchFieldFocus(true)" onBlur="searchPanel.OnSearchFieldFocus(false)" onKeyUp="searchPanel.OnSearchFieldChange()"><select id=MSearchType onFocus="searchPanel.OnSearchTypeFocus(true)" onBlur="searchPanel.OnSearchTypeFocus(false)" onChange="searchPanel.OnSearchTypeChange()"><option  id=MSearchEverything selected value="General">Everything</option><option value="Classes">Classes</option><option value="Constants">Constants</option><option value="Functions">Functions</option><option value="Properties">Properties</option><option value="Types">Types</option><option value="Variables">Variables</option></select></div><script language=JavaScript><!--
HideAllBut([1], 6);// --></script></div><!--Menu-->



<!--START_ND_TOOLTIPS-->
<div class=CToolTip id="tt1"><div class=CSection>Bits of code to do things related to NewAC.</div></div><!--END_ND_TOOLTIPS-->




<div id=MSearchResultsWindow><iframe src="" frameborder=0 name=MSearchResults id=MSearchResults></iframe><a href="javascript:searchPanel.CloseResultsWindow()" id=MSearchResultsWindowClose>Close</a></div>


<script language=JavaScript><!--
if (browserType) {if (browserVer) {document.write("</div>"); }document.write("</div>");}// --></script></body></html>